package com.zzyl.mapper;

import com.github.pagehelper.Page;
import com.zzyl.dto.VisitDto;
import com.zzyl.entity.customer.Member;
import com.zzyl.entity.visit.Reservation;
import com.zzyl.entity.visit.Visit;
import com.zzyl.vo.ReservationVo;
import com.zzyl.vo.TimeCountVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface ReservationMapper {
	
	int insert(Reservation reservation);
	
	int update(Reservation reservation);
	
	int deleteById(Long id);
	
	Reservation findById(Long id);
	
	List<Reservation> findAll(@Param("createBy") Long userId, @Param("mobile") String mobile, @Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);
	
	Page<Reservation> findByPage(@Param("page") int startIndex, @Param("pageSize") int pageSize, @Param("name") String name, @Param("mobile") String mobile, @Param("status") Integer status, @Param("type") Integer type, @Param("createBy") Long userId, @Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);
	
	int countReservationsWithinTimeRange(@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime, @Param("createBy") Long createBy, @Param("status") Integer status);
	
	List<TimeCountVo> countReservationsByTimeRange(@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);
	
	int countCancelledReservationsWithinTimeRange(@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime, @Param("updateBy") Long updateBy);
	
	@Update("update zzyl.vis_reservation set status = 3 where time <#{minusDays}")
	void updateReservationStatus(LocalDateTime minusDays);
	
	
	@Select("select status from zzyl.vis_reservation where name = #{name}")
	Integer cancelledCount(String name);


	void foundName(ReservationVo reservationVo);

	List<TimeCountVo> countByTime(String format);

	void postCount(Visit visit);
	@Select("select time from vis_reservation where mobile = #{mobile}")
	LocalDateTime postCountPhone(String mobile);
	@Select("select name from inout_retreat where name = #{name};")
	Object inoutRetreat(String name);
	
@Update("update vis_reservation set status=2 where id=#{id}")
	void clearCount(Long id);

	Page<ReservationVo> pageCount(Integer status, Long userId);
}
